/**
 * 2013-6-23 下午5:47:40 Created By niexiaoqiang
 */

package com.xiaoqiang.util.mtwmail;

import java.util.ArrayList;

import android.os.Looper;

import com.xiaoqiang.MtwV2ForMoblie.MainActivity;
import com.xiaoqiang.util.Logger;

/**
 * 邮件发送线程
 */
public class MtwMailSender extends Thread {

	private String subject, content, to;
	ArrayList<String> filenames;
	private static Logger log = new Logger(MainActivity.class);

	public MtwMailSender(String subject, String content, String to, ArrayList<String> filenames) {
		this.subject = subject;
		this.content = content;
		this.to = to;
		this.filenames = filenames;
	}

	public MtwMailSender(String subject, String content, String to) {
		this.subject = subject;
		this.content = content;
		this.to = to;
		this.filenames = null;
	}

	public void send() {
		this.start();
	}

	@Override
	public void run() {
		Looper.prepare();
		try {
			GMail mailSend = new GMail();
			if (null == filenames || filenames.size() < 1) {
				mailSend.sendMail(subject, content, to);
			} else {
				mailSend.sendMail(subject, content, to, filenames);
			}
			log.info("mail send successed!!");
		}
		catch (Exception e) {
			log.error("mail send failed!!");
			log.error(e);
		}
	}
}
